<?php
/**
 * 商户
 * User: chen guang
 * Date: 2017/9/29 9:00
 *
 */

namespace app\admin\controller;


use think\Db;

class Set extends Common{
	
	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();

	}

	/**
	 * 轮播图
	 */
	public function bannerlist(){
		$banner = db('banner');
		$ban = $banner->select();
		$this -> assign("res",$ban);
		return $this->fetch();
	}
	/**
	 * 轮播添加或修改
	 */
	public function banner_edit(){
		$id = input('id');
		if(request()->isPost()){
			$data['status'] = input('post.status');
			$data['title'] = input('post.title');
			$data['sort'] = input('post.displayorder');
			$data['url'] = input('post.url');
			$file = request()->file('bnimage');
			if (!empty($file)) {
				$info = $file->move(ROOT_IMG_PATH .'static/uploads');
				if ($info) {
					$data['pic'] = $info->getSaveName();
				} else {
					$this->success($file->getError());
				}
			} else {
				$data['pic'] = input('bne');
			}
			if($id){
				$bnr = db('banner')->where("id='$id'")->update($data);
			}else{
				$bnr = db('banner')->insert($data);
			}
			$this->success("操作成功!",url('Set/bannerlist'));
		}
		$banner=db('banner')->where("id='$id'")->find();
		$this -> assign("banner",$banner);
		return $this->fetch();

	}
	/**
	 * 轮播删除
	 */
	public function banner_del(){
		$bnid = input('get.id');
		$banner = db('banner');
		$del = $banner -> where("id='$bnid'") -> delete();
		$this -> success("删除成功",url('Set/bannerlist'));
	}



}